package com.sky.service.user.impl;

import com.sky.dto.CategoryPageQueryDTO;
import com.sky.mapper.user.UserCategoryMapper;
import com.sky.pojo.Category;
import com.sky.service.user.UserCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
@Slf4j
public class UserCategoryServiceImpl implements UserCategoryService {
    @Autowired
    private UserCategoryMapper userCategoryMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<Category> findList() {
        List<Category> categoryList = (List<Category>) redisTemplate.opsForValue().get("Category");
        if (!CollectionUtils.isEmpty(categoryList)){
            log.info("从Redis查询");
            return categoryList;
        }
        categoryList = userCategoryMapper.findList();
        redisTemplate.opsForValue().set("Category",categoryList);
        return categoryList;
    }
}
